package com.qqgame.hlddz;

import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class PoiCNaviActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SharedPreferences sharedPreferences = getSharedPreferences("MyPreferences", MODE_PRIVATE);
        String display2AppValue = sharedPreferences.getString("display2App", "1");

        String Lat = sharedPreferences.getString("poiCLat", "");
        String Lon = sharedPreferences.getString("poiCLon", "");
        String poiName = sharedPreferences.getString("poiCName", "");

        if ("1".equals(display2AppValue) || "".equals(display2AppValue)) {
            gaoDeNavi(Lat, Lon);
        }
        if ("2".equals(display2AppValue)) {
            baiduNavi(Lat, Lon, poiName);
        }
        if ("3".equals(display2AppValue)) {
            gaoDeNavi(Lat, Lon);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            baiduNavi(Lat, Lon, poiName);
        }

        finish();

    }

    public void gaoDeNavi(String lat, String lon) {
        Intent secondIntent = new Intent();
        ComponentName cn = new ComponentName("com.autonavi.amapautp", "com.autonavi.amapauto.MainMapActivity");
        secondIntent.setComponent(cn); //该句很重要，不添加则无法推送到副屏
        secondIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        secondIntent.setData(Uri.parse("androidauto://navi?sourceApplication=Speech&dev=0&poiname=&lat="+lat+"&lon="+lon));
        startActivity(secondIntent);
    }

    public void baiduNavi(String lat, String lon, String poiName) {
        if (poiName == null || "".equals(poiName)) {
            poiName = "目的地";
        }
        Intent secondIntent = new Intent();
        secondIntent.setData(Uri.parse("baidumap://map/navi?location=" + lat + "," + lon + "&coord_type=gcj02&query=" + poiName + "&src=webapp.companyName.appName"));
        startActivity(secondIntent);
    }


}